<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />  
        <title>Railway Official Website</title>
        <link rel="stylesheet" href="css/foundation.css"/>
        <link rel="stylesheet" href="css/normalize.css"/>
        <link rel="stylesheet" href="css/jquery-ui.css" />
        <script src="js/vendor/jquery.js"></script>
        <script src="js/ui/jquery-ui.js"></script>
        <script src="js/vendor/custom.modernizr.js"></script>
        <script src="js/foundation.min.js"></script>
        <script src="js/ticketing.js"></script>
        <script src="js/printThis.js"></script>
        <?php
        session_start();
        ?>
        <script>

        </script>
    </head>
    <body>
        <div id="myModal" class="reveal-modal medium" style="height: 500px;">
            <form class="custom" id="seatform">
                <input type="hidden" id="ticketnumber"/>
                <input type="hidden" name="action" value="getCoachmap"/>
                <div class="row">
                    <div class="row">
                        <div class="small-3 columns">
                            <label for="coach" class="inline">Select Coach  :</label>
                        </div>
                        <div class="small-4 left columns">
                            <select id="coach" name="coach" onchange="getCoachmap();">
                                <option value="0">Select Coach</option>
                            </select>
                        </div>
                    </div>
                    <div class="row">
                        <div id="coachmap" class="row" style="height: 415px; overflow: auto;">

                        </div>
                    </div>
                </div>
            </form>
            <a class="close-reveal-modal">&#215;</a>
        </div>
        <div id='overlay' style="display:none; opacity: 0.4;position: absolute;top: 0;left: 0;background-color: black;width: 100%;z-index: 5000;">
            <img src="img/loader.gif" style="opacity:1; position: absolute; top: 50%;left: 50%;margin-left:-16px;
                 margin-top:-16px';"><span>Please wait...</span></img>
        </div>
        <div>
            <nav class="top-bar">
                <ul class="title-area">
                    <li class="name" onClick="void(0);">
                        <h1><a href="#">Railway Official Website</a></h1>
                    </li>
                    <li class="divider"></li>
                    <li class="toggle-topbar menu-icon">
                        <a href="#"><span>menu</span></a>
                    </li>
                </ul>
                <section class="top-bar-section">
                    <ul class="right">
                        <li class="divider"></li>
                        <li><a href="index.php">Home</a></li>
                        <li class="divider"></li>
                        <li><a href="index.php">Forum</a></li>
                        <li class="divider"></li>
                        <?php
                        if (isset($_SESSION['username'])) {
                            echo '<li><a href="profile.php?mode=21">My profile</a></li>';
                            echo '<li class="divider"></li>';
                            echo '<li><a href="logout.php">Logout</a></li>';
                            echo '<li class="divider"></li>';
                        }
                        else
                            echo '<li><a href="loginPage.php">Login</a></li>';
                        echo '<li class="divider"></li>';
                        ?>
                    </ul>
                </section>
            </nav>
        </div>
        <div class="row">
            <?php
            if (isset($_SESSION['username']) && isset($_SESSION['qrcode'])) {
                $code = $_SESSION['qrcode'];
                $count = count($code);
                require_once 'classes/Ticket.php';
                $t = new Ticket();
                ?>
                <div class="columns">
                    <div class="row">
                        <div class="large-9 push-3 columns">
                            <div class="row">
                                <div class="large-11 large-offset-1 columns">
                                    <h4>Ticket successfully purchased</h4>
                                    <hr/>
                                    <h6 class="subheader">Click print ticket to print out the ticket, otherwise, you can save the images in your smartphone.</h6>
                                    <div class="row panel">
                                        <div id="printable" class="large-12 columns">
                                            <?php
                                            $ticket = '<div class="row">';
                                            for ($i = 0; $i < $count; $i++) {
                                                $seat = $t->getSeatAndCoach($code[$i]);
                                                $ticket.= '<div class="large-6 columns">' .
                                                        '<label>Ticket No.' . ($i + 1) . '</label><br/>' .
                                                        '<label>Seat : ' . $seat['coach'] . ' - ' . $seat['seatNo'] . '</label><br/>' .
                                                        '<img src="qrgenerator.php?param=' . $code[$i] . '"/><br/>' .
                                                        '</div>';
                                                if (($i + 1) % 2 == 0) {
                                                    $ticket .= '</div>' .
                                                            '<hr/>' .
                                                            '<div class="row">';
                                                }
                                            }
                                            $ticket .= '</div>';
                                            echo $ticket;
                                            unset($_SESSION['qrcode']);
                                            ?>
                                        </div>
                                        <div class=" large-12 columns">
                                            <br/>
                                            <input type="button" value="Print ticket" class="small right button" onclick="$('#printable').printThis();"/>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="large-3 pull-9 columns panel">
                            <a href="profile.php?mode=21"><h5>User Profile</h5></a>
                            <ul class="side-nav">
                                <li><a href="profile.php?mode=22">Change password</a></li>
                                <li class="divider"></li>
                                <li><a href="profile.php?mode=23">Maintain profile</a></li>
                                <li class="divider"></li>
                                <li><a href="profile.php?mode=24">Point redemption</a></li>
                                <li class="divider"></li>
                                <li><a href="profile.php?mode=25">Reload account</a></li>
                                <li class="divider"></li>
                                <li class="active"><a href="profile.php?mode=26">Purchase ticket</a></li>
                                <li class="divider"></li>
                                <li><a href="viewticket.php?mode=viewall">View ticket history</a></li>
                            </ul>
                        </div>
                    </div>
                </div>
                <?php
            } elseif (isset($_SESSION['username']) && isset($_POST['success'])) {
                $amount = $_POST['amount'];
                require_once 'classes/Member.php';
                $m = new Member();
                ?>
                <div class="columns">
                    <div class="row">
                        <div class="large-9 push-3 columns">
                            <div class="row">
                                <div class="large-11 large-offset-1 columns panel">
                                    <?php
                                    $result = $m->updateBalance($amount, $_SESSION['uid']);
                                    if ($result) {
                                        ?>
                                        <p>Reload successful, click <a href="profile.php?mode=21">here</a> to go back to profile.</p>
                                        <?php
                                    } else {
                                        ?>
                                        <p>Reload unsuccessful, please contact the administrator.</p>
                                        <?php
                                    }
                                    ?>
                                </div>
                            </div>
                        </div>
                        <div class="large-3 pull-9 columns panel">
                            <a href="profile.php?mode=21"><h5>User Profile</h5></a>
                            <ul class="side-nav">
                                <li><a href="profile.php?mode=22">Change password</a></li>
                                <li class="divider"></li>
                                <li><a href="profile.php?mode=23">Maintain profile</a></li>
                                <li class="divider"></li>
                                <li><a href="profile.php?mode=24">Point redemption</a></li>
                                <li class="divider"></li>
                                <li class='active'><a href="profile.php?mode=25">Reload account</a></li>
                                <li class="divider"></li>
                                <li><a href="profile.php?mode=26">Purchase ticket</a></li>
                                <li class="divider"></li>
                                <li><a href="viewticket.php?mode=viewall">View ticket history</a></li>
                            </ul>
                        </div>
                    </div>
                </div>
                <?php
            } elseif (isset($_SESSION['username']) && isset($_GET['refund'])) {
                ?>
                <div class="columns">
                    <div class="row">
                        <div class="large-9 push-3 columns">
                            <div class="row">
                                <div class="large-11 large-offset-1 columns panel">
                                    <?php
                                    if ($_GET['refund']) {
                                        ?>
                                        <p>Ticket with reference number <?php echo str_pad($_GET['referenceno'], 10, '0', STR_PAD_LEFT); ?> has been successfully cancelled</p>
                                        <p>Your new account balance is RM<?php echo $_GET['balance']; ?></p>
                                        <?php
                                    } else {
                                        ?>
                                        <p>Refund unsuccessful, please contact the adminstrator.</p>
                                        <?php
                                    }
                                    ?>
                                </div>
                            </div>
                        </div>
                        <div class="large-3 pull-9 columns panel">
                            <a href="profile.php?mode=21"><h5>User Profile</h5></a>
                            <ul class="side-nav">
                                <li><a href="profile.php?mode=22">Change password</a></li>
                                <li class="divider"></li>
                                <li><a href="profile.php?mode=23">Maintain profile</a></li>
                                <li class="divider"></li>
                                <li><a href="profile.php?mode=24">Point redemption</a></li>
                                <li class="divider"></li>
                                <li><a href="profile.php?mode=25">Reload account</a></li>
                                <li class="divider"></li>
                                <li><a href="profile.php?mode=26">Purchase ticket</a></li>
                                <li class="divider"></li>
                                <li><a href="viewticket.php?mode=viewall">View ticket history</a></li>
                            </ul>
                        </div>
                    </div>
                </div>
                <?php
            } elseif (isset($_SESSION['username']) && isset($_GET['amend'])) {
                ?>
                <div class="columns">
                    <div class="row">
                        <div class="large-9 push-3 columns">
                            <div class="row">
                                <div class="large-11 large-offset-1 columns panel">
                                    <?php
                                    if ($_GET['amend']) {
                                        ?>
                                        <p>Ticket with reference number <?php echo str_pad($_GET['referenceno'], 10, '0', STR_PAD_LEFT); ?> has been successfully amended.</p>
                                        <p>Use this as the new amended ticket</p>
                                        <p><img src="qrgenerator.php?param=<?php echo $_GET['qrcode']; ?>"</p>
                                        <?php
                                    } else {
                                        ?>
                                        <p>Amend unsuccessful, please contact the adminstrator.</p>
                                        <?php
                                    }
                                    ?>
                                </div>
                            </div>
                        </div>
                        <div class="large-3 pull-9 columns panel">
                            <a href="profile.php?mode=21"><h5>User Profile</h5></a>
                            <ul class="side-nav">
                                <li><a href="profile.php?mode=22">Change password</a></li>
                                <li class="divider"></li>
                                <li><a href="profile.php?mode=23">Maintain profile</a></li>
                                <li class="divider"></li>
                                <li><a href="profile.php?mode=24">Point redemption</a></li>
                                <li class="divider"></li>
                                <li><a href="profile.php?mode=25">Reload account</a></li>
                                <li class="divider"></li>
                                <li><a href="profile.php?mode=26">Purchase ticket</a></li>
                                <li class="divider"></li>
                                <li><a href="viewticket.php?mode=viewall">View ticket history</a></li>
                            </ul>
                        </div>
                    </div>
                </div>
                <?php
            } elseif (isset($_SESSION['username'])) {
                ?>
                <div class="columns">
                    <div class="row">
                        <div class="large-9 push-3 columns">
                            <div class="row">
                                <div class="large-11 large-offset-1 columns panel">
                                    You have nothing to do here, click <a href="index.php">here</a> to return to home page, or <a href="profile.php?mode=21">here</a> to return to your profile.
                                </div>
                            </div>
                        </div>
                        <div class="large-3 pull-9 columns panel">
                            <a href="profile.php?mode=21"><h5>User Profile</h5></a>
                            <ul class="side-nav">
                                <li><a href="profile.php?mode=22">Change password</a></li>
                                <li class="divider"></li>
                                <li><a href="profile.php?mode=23">Maintain profile</a></li>
                                <li class="divider"></li>
                                <li><a href="profile.php?mode=24">Point redemption</a></li>
                                <li class="divider"></li>
                                <li><a href="profile.php?mode=25">Reload account</a></li>
                                <li class="divider"></li>
                                <li><a href="profile.php?mode=26">Purchase ticket</a></li>
                                <li class="divider"></li>
                                <li><a href="viewticket.php?mode=viewall">View ticket history</a></li>
                            </ul>
                        </div>
                    </div>
                </div>
                <?php
            } else {
                ?>
                <div class="row">
                    <div class="large-10 large-offset-1 columns panel">
                        You do not have the permission to access this page, please <a href="loginPage.php">login</a> first.
                        <?php
                        if (isset($_SERVER['HTTP_REFERER'])) {
                            echo '<br/>Click <a href="' . $_SERVER['HTTP_REFERER'] . '">here</a> to back to previous page.';
                        }
                        ?>
                    </div>
                </div>
                <?php
            }
            ?>

        </div>
        <footer class="row">
            <div class="large-12 columns">
                <hr />
                <div class="row">
                    <div class="large-4 columns">
                        <p>&copy; Copyright 2013.</p>
                    </div>
                    <div class="large-6 columns">
                        <ul class="inline-list right">
                            <li><a href="aboutus.php">About Us</a></li>
                            <li><a href="contactus.php">Contact Us</a></li>
                            <li><a href="terms.php">Terms and Condition</a></li>
                        </ul>
                    </div>
                </div>
            </div>
        </footer>
        <script>
            $(document).foundation();
        </script>
    </body>
</html>